Fix repr of Signature so it works for subclasses#1552
Closed
robtaylor wants to merge 1 commit into
Closed
Conversation
whitequark
requested changes
Jul 3, 2025
Member
whitequark
left a comment
There was a problem hiding this comment.
Apologies, it seems like I've never submitted a review.
| def __repr__(self): | ||
| if type(self) is Signature: | ||
| if isinstance(self, Signature): | ||
| return f"Signature({dict(self.members.items())})" |
Member
There was a problem hiding this comment.
This isn't a correct fix. There are two problems with it.
- A repr is supposed to give information about the class name as well. Your fix would incorrectly indicate that the class name is
Signaturerather than whatever the subclass is. - Subclassing
Signatureis only really useful if you're going to add non-member attributes to it. But the default implementation only prints members. The check here serves as a nudge to implementers to make sure they really did cover all attributes.
Author
|
Makes sense :)
…On Thu, 3 Jul 2025 at 02:40, Catherine ***@***.***> wrote:
***@***.**** requested changes on this pull request.
Apologies, it seems like I've never submitted a review.
------------------------------
In amaranth/lib/wiring.py
<#1552 (comment)>
:
> @@ -1002,7 +1002,7 @@ def annotations(self, obj, /):
return tuple()
def __repr__(self):
- if type(self) is Signature:
+ if isinstance(self, Signature):
return f"Signature({dict(self.members.items())})"
This isn't a correct fix. There are two problems with it.
1. A repr is supposed to give information about the class name as
well. Your fix would incorrectly indicate that the class name is
Signature rather than whatever the subclass is.
2. Subclassing Signature is only really useful if you're going to add
non-member attributes to it. But the default implementation only prints
members. The check here serves as a nudge to implementers to make sure they
really did cover all attributes.
—
Reply to this email directly, view it on GitHub
<#1552 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAB4O4C2U37WFHUPYWVJ62D3GR3WBAVCNFSM6AAAAABVNNNPK6VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDSOBRGA2DQOJWGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
At the moment the
__repr__forSignaturedoesn't work for derived classes ofSignature(as used e.g. in Glasgow).Simple fix here.